/******************************************************************************
Purpose: 		To prep and merge individual country files from 
				Violence Against Children Surveys (VACS)
				and run analyses specified in the paper
Paper Title:	Adolescent Girls’ Safety In and Out of School: 
				Evidence on Physical and Sexual Violence
				from across Sub-Saharan Africa		
Authors:		Evans D.K., Hares S., Holland P. A., and Mendez Acosta A.
Journal:		Journal of Development Studies (forthcoming)
Input:			Individual country level files in one folder ("VACS")
				for the 6 countries covered in the analysis.
Output:			Merged VACS DTA file
				Tables of statistics (Log file in PDF and Excel files)
*******************************************************************************/

/**************************************
00. Housekeeping
***************************************/

* clear memory
	version 16.1
	clear
	clear 	matrix
	clear 	mata
	clear 	results
	set		more off
	set 	maxvar 30000

* set path files
	global parentfolder 	"INSERT FOLDER LOCATION HERE AND FOLDER NAME HERE"
	
	* FOR EXAMPLE:
	* global parentfolder 	"/Users/Downloads/Adolescent Girls’ Safety In and Out of School_Replication Files"


* globals and locals
	global 	outputfile	"VACS_merged.dta"
	global	logfile		"VACS_logfile"	

* log file
	capture log close _all
	log using "$parentfolder/$logfile", replace
	
/**************************************************
 01. Append VACS country files
**************************************************/
		
	* save blank file
		gen 	blankvar=.
		cd 		"$parentfolder"
		save 	"$outputfile", replace
		
	* clean each country file and append to the blankfile
	
		*************** KENYA 2010 **********************
		{
			use "$parentfolder/VACs/kenya_finaldta_fem_pubusev.dta", clear
			
			ren F2 age
			keep if age >= 13 & age <= 19
			
			ren F32 inschool
			recode inschool (2 = 0) (98/99 = .)
			
			egen hhid = group(provincecode cluster HOHAge hohdob HOHSex)
			
			rename Finalwgt finalwgt
			
			gen country = "Kenya"
			
			***** physical violence in the past 12 months *****
			
				* from partner
				gen phy_partner = .
				replace phy_partner = 0 if inrange(F102_A, 1, 2) | inrange(F103_A, 1, 2) | inrange(F104_A, 1, 2)  // answered yes (1) or no (2) to having experienced violence ; dropping missing answers
				replace phy_partner = 1 if F102_D == 1 | F103_D == 1 | F104_D == 1 // first or most recent happened in the last 12 months
				
				* from relatives
				gen phy_relatives = .
				replace phy_relatives = 0 if inrange(F106_A, 1, 2) | inrange(F107_A, 1, 2) // answered yes (1) or no (2) to having experienced violence; dropping missing answers
				replace phy_relatives = 1 if F106_D == 1 | F107_D == 1 // first or most recent happened in the last 12 months
				
				* from other adults
				gen phy_other = .
				replace phy_other = 0 if inrange(F109_A, 1, 2) | inrange(F110_A, 1, 2) // answered yes (1) or no (2) to having experienced violence; dropping missing answers
				replace phy_other = 1 if F109_D == 1 | F110_D == 1 // first or most recent happened in the last 12 months
				
				* from non-partners
				gen phy_nonpartner = 0
				replace phy_nonpartner = 1 if phy_relatives == 1 | phy_other == 1
						
				* at least one incident in the past 12 months
				gen phy_violence = 0
				replace phy_violence = 1 if phy_partner == 1 | phy_relatives == 1 | phy_other == 1
				
				* who are the "other adults"?
				gen phy_o_teacher = . if phy_violence == .
				replace phy_o_teacher = 0 if phy_violence != .
				replace phy_o_teacher = 1 if F109_E1 == 1 & F109_D == 1 // teacher punched you, kicked you, whipped you, or beat you with an object in the past 12 months
				replace phy_o_teacher = 1 if F110_E1 == 1 & F110_D == 1 // teacher used or threatened to use a knife or other weapon against you in the past 12 months
				//br phy_violence F109_E1 F109_D F110_E1 F110_D phy_o_teacher
				
				gen phy_o_police = . if phy_violence == .
				replace phy_o_police = 0 if phy_violence != .
				replace phy_o_police = 1 if F109_E2 == 1 & F109_D == 1 // police punched you, kicked you, whipped you, or beat you with an object in the past 12 months
				replace phy_o_police = 1 if F110_E2 == 1 & F110_D == 1 // police used or threatened to use a knife or other weapon against you in the past 12 months
				
				gen phy_o_military = . if phy_violence == . // drop from sample those who refused to answer any physical violence question
				replace phy_o_military = 0 if phy_violence != .
				replace phy_o_military = 1 if F109_E3 == 1 & F109_D == 1 // military punched you, kicked you, whipped you, or beat you with an object in the past 12 months
				replace phy_o_military = 1 if F110_E3 == 1 & F110_D == 1 // military used or threatened to use a knife or other weapon against you in the past 12 months
				
				gen phy_o_employer = . if phy_violence == . // drop from sample those who refused to answer any physical violence question
				replace phy_o_employer = 0 if phy_violence != .
				replace phy_o_employer = 1 if F109_E4 == 1 & F109_D == 1 // employer punched you, kicked you, whipped you, or beat you with an object in the past 12 months
				replace phy_o_employer = 1 if F110_E4 == 1 & F110_D == 1 // employer used or threatened to use a knife or other weapon against you in the past 12 months
				
				gen phy_o_communityelder = . if phy_violence == . // drop from sample those who refused to answer any physical violence question
				replace phy_o_communityelder = 0 if phy_violence != .
				replace phy_o_communityelder = 1 if F109_E5 == 1 & F109_D == 1 // communityelder punched you, kicked you, whipped you, or beat you with an object in the past 12 months
				replace phy_o_communityelder = 1 if F110_E5 == 1 & F110_D == 1 // communityelder used or threatened to use a knife or other weapon against you in the past 12 months
					
				gen phy_o_religiousleader = . if phy_violence == . // drop from sample those who refused to answer any physical violence question
				replace phy_o_religiousleader = 0 if phy_violence != .
				replace phy_o_religiousleader = 1 if F109_E6 == 1 & F109_D == 1 // religiousleader punched you, kicked you, whipped you, or beat you with an object in the past 12 months
				replace phy_o_religiousleader = 1 if F110_E6 == 1 & F110_D == 1 // religiousleader used or threatened to use a knife or other weapon against you in the past 12 months
				
				gen phy_o_other = . if phy_violence == . // drop from sample those who refused to answer any physical violence question
				replace phy_o_other = 0 if phy_violence != .
				replace phy_o_other = 1 if F109_E7 == 1 & F109_D == 1 // other punched you, kicked you, whipped you, or beat you with an object in the past 12 months
				replace phy_o_other = 1 if F110_E7 == 1 & F110_D == 1 // other used or threatened to use a knife or other weapon against you in the past 12 months
						
			***** sexual violence in the past 12 months *****	
			
				* forced touch
				gen forced_touch = .
				replace forced_touch = 0 if F301 == 0 // never attempted
				replace forced_touch = 1 if F323 == 1 //first time happened in the last 12 months
				replace forced_touch = 0 if F323 == 2 //first time did not happen in the last 12 months
				replace forced_touch = 1 if F309 == 1 //most recent happened in the last 12 months
				replace forced_touch = 0 if F309 == 2 //most recent did not happen in the last 12 months
				
				* attempted sex
				
				gen attempted_sex = . // attempted sex without consent
				replace attempted_sex = 0 if F401 == 0 // never attempted
				replace attempted_sex = 1 if F424 == 1 // first time happened in the last 12 months
				replace attempted_sex = 0 if F424 == 2 // first time did not happen in the last 12 months
				replace attempted_sex = 1 if F409 == 1 // most recent happened in the last 12 months
				replace attempted_sex = 0 if F409 == 2 // most recent did not happen in the last 12 months
				
				
				* forced sex
				gen forced_sex = .
				replace forced_sex = 0 if F501 == 0 // never attempted
				replace forced_sex = 1 if F528 == 1 //first time happened in the last 12 months
				replace forced_sex = 0 if F528 == 2 //first time did not happen in the last 12 months
				replace forced_sex = 1 if F513 == 1 //most recent happened in the last 12 months
				replace forced_sex = 0 if F513 == 2 //most recent did not happen in the last 12 months	
				
				* pressured sex
				gen pressured_sex = .
				replace pressured_sex = 0 if F601 == 0 // never attempted
				replace pressured_sex = 1 if F629 == 1 //first time happened in the last 12 months
				replace pressured_sex = 0 if F629 == 2 //first time did not happen in the last 12 months
				replace pressured_sex = 1 if F613 == 1 //most recent happened in the last 12 months
				replace pressured_sex = 0 if F613 == 2 //most recent did not happen in the last 12 months	
				
				* at least one incident in the past 12 months
				gen sex_violence = 0 //ever been sexually abused in the past 12 months; i.e. most recent abuse is in the past 12 months
				replace sex_violence = 1 if forced_touch == 1 | attempted_sex == 1 | forced_sex == 1 | pressured_sex == 1
				
				
			*****  physical or sexual violence ***** 
				gen violence = 0
				replace violence = 1 if sex_violence == 1 | phy_violence == 1
				
				
			***** sexual violence in the past 12 months in school ***** 
				
				* forced touch
				gen forcedtouch_inschool = .
				replace forcedtouch_inschool = 0 if F309 == 1 // most recent in 12 months
				replace forcedtouch_inschool = 1 if F309 == 1 & F307 == 6 // most recent in 12 months and in school
				replace forcedtouch_inschool = 0 if F323 == 1 //first time in 12 monthsschool
				replace forcedtouch_inschool = 1 if F323 == 1 & F320 == 6 // first time in 12 months and in school
			
				* attempted sex
				gen attemptedsex_inschool = .
				replace attemptedsex_inschool = 0 if F409 == 1 // most recent in 12 months
				replace attemptedsex_inschool = 1 if F409 == 1 & F407 == 6 // most recent in 12 months and in school
				replace attemptedsex_inschool = 0 if F424 == 1 //first time in 12 monthsschool
				replace attemptedsex_inschool = 1 if F424 == 1 & F421 == 6 // first time in 12 months and in school
				
				* forced sex
				gen forcedsex_inschool = .
				replace forcedsex_inschool = 0 if F513 == 1 // most recent in 12 months
				replace forcedsex_inschool = 1 if F513 == 1 & F511 == 6 // most recent in 12 months and in school
				replace forcedsex_inschool = 0 if F528 == 1 //first time in 12 monthsschool
				replace forcedsex_inschool = 1 if F528 == 1 & F525 == 6 // first time in 12 
				
				* pressured sex
				gen pressuredsex_inschool = .
				replace pressuredsex_inschool = 0 if F613 == 1 // most recent in 12 months
				replace pressuredsex_inschool = 1 if F613 == 1 & F611 == 6 // most recent in 12 months and in school
				replace pressuredsex_inschool = 0 if F629 == 1 //first time in 12 monthsschool
				replace pressuredsex_inschool = 1 if F629 == 1 & F626 == 6 // first time in 12 
				
				* violence in school
				gen sv_inschool = .
				replace sv_inschool = 0  if sex_violence == 1 //violence happened in the past year
				replace sv_inschool = 1 if forcedtouch_inschool == 1 | attemptedsex_inschool == 1 | forcedsex_inschool == 1 | pressuredsex_inschool == 1 //violence happened in the past year AND in school
			
			* additional controls
			
				* female-headed household
				 gen f_hoh = .
				 replace f_hoh = 1 if HOHSex == "Female"
				 replace f_hoh = 0 if HOHSex == "Male"
				 
				 * not with bio mom
				 gen not_wmom = .
				 replace not_wmom = 1 if F19 == 2
				 replace not_wmom = 0 if F19 == 1
				 
				 * not with bio dad
				 gen not_wdad = .
				 replace not_wdad = 1 if F24 == 2
				 replace not_wdad = 0 if F24 == 1
				 
				 * # of adults and children
				 
				  forvalues i = 1(1)20 {
					generate adult`i' = .
					replace adult`i' = 1 if HHM`i'Age >= 18 & HHM`i'Age < .
					
					generate child`i' = .
					replace child`i' = 1 if HHM`i'Age >= 0 & HHM`i'Age < 18
				  }
				 
				 egen adult_n = rowtotal(adult*)
				 egen child_n = rowtotal(child*)		
				 
				 * controls similar to DHS
				 rename H31 dist_clinic
				 
				 destring H15 H4 H10_A H10_B H10_C H11_A, replace
				 rename H15 highest_schooling
				 recode highest_schooling (9 = .)
				 
				 gen electricity = (H4 == 1)
				 gen radio = (H10_A == 1)
				 gen bicycle = (H11_A == 1)
				 gen tv = (H10_B == 1)
				 gen phone = (H10_C == 1)
		}
			append using "$parentfolder/$outputfile", force	// Appending the country file to the main file
			save "$parentfolder/$outputfile", replace		

		*************** MALAWI 2013 **********************
		{
			use "$parentfolder/VACs/mwfemale_pubuse.dta", clear

			ren Q2 age
			keep if age >= 13 & age <= 19
			
			ren Q4 inschool
			recode inschool (2 = 0) (98/99 = .)
			
			gen hhid = hh
			
			rename Finalwgt finalwgt

			gen country = "Malawi"
			
			***** physical violence in the past 12 months *****
				
				* from partner
				gen phy_partner = .
				replace phy_partner = 0 if inrange(Q100A, 1, 2) | inrange(Q100B, 1, 2) | inrange(Q100C, 1, 2) // answered yes (1) or no (2) to having experienced violence ; dropping missing answers
				replace phy_partner = 1 if Q102 == 1 | Q109 == 1 // first or most recent happened in the last 12 months
				* from peers
				gen phy_peers = .
				replace phy_peers = 0 if inrange(Q116A, 1, 2) | inrange(Q116B, 1, 2) | inrange(Q116C, 1, 2) // answered yes (1) or no (2) to having experienced violence; dropping missing answers
				replace phy_peers = 1 if Q118 == 1 | Q123 == 1 // first or most recent happened in the last 12 months
				
				* from relatives
				gen phy_relatives = .
				replace phy_relatives = 0 if inrange(Q128A, 1, 2) | inrange(Q128B, 1, 2) | inrange(Q128C, 1, 2) // answered yes (1) or no (2) to having experienced violence; dropping missing answers
				replace phy_relatives = 1 if Q130 == 1 | Q136 == 1 // first or most recent happened in the last 12 months
				
				* from other adults
				gen phy_other = .
				replace phy_other = 0 if inrange(Q142A, 1, 2) | inrange(Q142B, 1, 2) | inrange(Q142C, 1, 2) // answered yes (1) or no (2) to having experienced violence; dropping missing answers
				replace phy_other = 1 if Q144 == 1 | Q149 == 1 // first or most recent happened in the last 12 months
				* at least one incident in the past 12 months
				gen phy_violence = 0
				replace phy_violence = 1 if phy_partner == 1| phy_peers == 1 |phy_relatives == 1 | phy_other == 1
				
				* from non-partners
				gen phy_nonpartner = 0
				replace phy_nonpartner = 1 if phy_peers == 1 |phy_relatives == 1 | phy_other == 1
				
				* who are the "other adults"?
				gen phy_o_teacher = . if phy_violence == .
				replace phy_o_teacher = 0 if phy_violence != .
				replace phy_o_teacher = 1 if inlist(Q146, 1, 7) & Q144 == 1 //most recent by a male or female teacher happened in the last 12 months
				replace phy_o_teacher = 1 if inlist(Q151, 1, 7) & Q149 == 1 //most recent by a male or female teacher happened in the last 12 months
				//br phy_violence Q146 Q144 Q151 Q149 phy_o_teacher
				
				gen phy_o_police = . if phy_violence == .
				replace phy_o_police = 0 if phy_violence != .
				replace phy_o_police = 1 if inlist(Q146, 2, 8) & Q144 == 1 //most recent by a male or female police happened in the last 12 months
				replace phy_o_police = 1 if inlist(Q151, 2, 8) & Q149 == 1 //most recent by a male or female police happened in the last 12 months
				
				gen phy_o_military = .	
			
				gen phy_o_employer = . if phy_violence == .
				replace phy_o_employer = 0 if phy_violence != .
				replace phy_o_employer = 1 if inlist(Q146, 3, 9) & Q144 == 1 //most recent by a male or female employer happened in the last 12 months
				replace phy_o_employer = 1 if inlist(Q151, 3, 9) & Q149 == 1 //most recent by a male or female employer happened in the last 12 months
				
				gen phy_o_communityelder = . if phy_violence == .
				replace phy_o_communityelder = 0 if phy_violence != .
				replace phy_o_communityelder = 1 if inlist(Q146, 4, 10) & Q144 == 1 //most recent by a male or female communityelder happened in the last 12 months
				replace phy_o_communityelder = 1 if inlist(Q151, 4, 10) & Q149 == 1 //most recent by a male or female communityelder happened in the last 12 months
				
				gen phy_o_religiousleader = . if phy_violence == .
				replace phy_o_religiousleader = 0 if phy_violence != .
				replace phy_o_religiousleader = 1 if inlist(Q146, 5, 11) & Q144 == 1 //most recent by a male or female religiousleader happened in the last 12 months
				replace phy_o_religiousleader = 1 if inlist(Q151, 5, 11) & Q149 == 1 //most recent by a male or female religiousleader happened in the last 12 months
				
				gen phy_o_other = . if phy_violence == .
				replace phy_o_other = 0 if phy_violence != .
				replace phy_o_other = 1 if inlist(Q146, 6, 12, 77, 88) & Q144 == 1 //most recent by a male or female other happened in the last 12 months
				replace phy_o_other = 1 if inlist(Q151, 6, 12, 77, 88) & Q149 == 1 //most recent by a male or female other happened in the last 12 months
				
						
			***** sexual violence in the past 12 months *****	
			
				* forced touch
				gen forced_touch = .
				replace forced_touch = 0 if Q700 == 2 // never attempted
				replace forced_touch = 1 if Q712 == 1 //first time happened in the last 12 months
				replace forced_touch = 0 if Q712 == 2 //first time did not happen in the last 12 months
				replace forced_touch = 1 if Q702 == 1 //most recent happened in the last 12 months
				replace forced_touch = 0 if Q702 == 2 //most recent did not happen in the last 12 months
				
				* attempted sex
				gen attempted_sex = . // attempted sex without consent
				replace attempted_sex = 0 if Q800 == 2 // never attempted
				replace attempted_sex = 1 if Q812 == 1 // first time happened in the last 12 months
				replace attempted_sex = 0 if Q812 == 2 // first time did not happen in the last 12 months
				replace attempted_sex = 1 if Q802 == 1 // most recent happened in the last 12 months
				replace attempted_sex = 0 if Q802 == 2 // most recent did not happen in the last 12 months
			
				* forced sex
				gen forced_sex = . // attempted sex without consent
				replace forced_sex = 0 if Q900 == 2 // never attempted
				replace forced_sex = 1 if Q915 == 1 //first time happened in the last 12 months
				replace forced_sex = 0 if Q915 == 2 //first time did not happen in the last 12 months
				replace forced_sex = 1 if Q902 == 1 //most recent happened in the last 12 months
				replace forced_sex = 0 if Q902 == 2 //most recent did not happen in the last 12 months	
				
				* pressured sex
				gen pressured_sex = . // attempted sex without consent
				replace pressured_sex = 0 if Q1000 == 2 // never attempted
				replace pressured_sex = 1 if Q1014 == 1 //first time happened in the last 12 months
				replace pressured_sex = 0 if Q1014 == 2 //first time did not happen in the last 12 months
				replace pressured_sex = 1 if Q1002 == 1 //most recent happened in the last 12 months
				replace pressured_sex = 0 if Q1002 == 2 //most recent did not happen in the last 12 months	
				
				* at least one incident in the past 12 months
				gen sex_violence = 0 //ever been sexually abused in the past 12 months; i.e. most recent abuse is in the past 12 months
				replace sex_violence = 1 if forced_touch == 1 | attempted_sex == 1 | forced_sex == 1 | pressured_sex == 1
				
				
			*****  physical or sexual violence ***** 
				gen violence = 0
				replace violence = 1 if sex_violence == 1 | phy_violence == 1
				
				
				
			***** sexual violence in the past 12 months in school ***** 
				
				* forced touch
				gen forcedtouch_inschool = .
				replace forcedtouch_inschool = 0 if Q702 == 1 // most recent in 12 months
				replace forcedtouch_inschool = 1 if Q702 == 1 & Q710 == 6 // most recent in 12 months and in school
				replace forcedtouch_inschool = 0 if Q712 == 1 //first time in 12 monthsschool
				replace forcedtouch_inschool = 1 if Q712 == 1 & Q720 == 6 // first time in 12 months and in school
			
				* attempted sex
				gen attemptedsex_inschool = .
				replace attemptedsex_inschool = 0 if Q802 == 1 // most recent in 12 months
				replace attemptedsex_inschool = 1 if Q802 == 1 & Q810 == 6 // most recent in 12 months and in school
				replace attemptedsex_inschool = 0 if Q812 == 1 //first time in 12 monthsschool
				replace attemptedsex_inschool = 1 if Q812 == 1 & Q820 == 6 // first time in 12 months and in school
				
				* forced sex
				gen forcedsex_inschool = .
				replace forcedsex_inschool = 0 if Q902 == 1 // most recent in 12 months
				replace forcedsex_inschool = 1 if Q902 == 1 & Q911 == 6 // most recent in 12 months and in school
				replace forcedsex_inschool = 0 if Q915 == 1 //first time in 12 monthsschool
				replace forcedsex_inschool = 1 if Q915 == 1 & Q924 == 6 // first time in 12 
				
				* pressured sex
				gen pressuredsex_inschool = .
				replace pressuredsex_inschool = 0 if Q1002 == 1 // most recent in 12 months
				replace pressuredsex_inschool = 1 if Q1002 == 1 & Q1010 == 6 // most recent in 12 months and in school
				replace pressuredsex_inschool = 0 if Q1014 == 1 //first time in 12 monthsschool
				replace pressuredsex_inschool = 1 if Q1014 == 1 & Q1022 == 6 // first time in 12 
				
				* violence in school
				gen sv_inschool = .
				replace sv_inschool = 0  if sex_violence == 1 //violence happened in the past year
				replace sv_inschool = 1 if forcedtouch_inschool == 1 | attemptedsex_inschool == 1 | forcedsex_inschool == 1 | pressuredsex_inschool == 1 //violence happened in the past year AND in school
			
			* additional controls
			
				* female-headed household
				 gen f_hoh = .
				 replace f_hoh = 1 if H2 == 2
				 replace f_hoh = 0 if H2 == 1
				 
				 * not with bio mom
				 gen not_wmom = .
				 replace not_wmom = 1 if Q14 == 2
				 replace not_wmom = 0 if Q14 == 1
				 
				 * not with bio dad
				 gen not_wdad = .
				 replace not_wdad = 1 if Q20 == 2
				 replace not_wdad = 0 if Q20 == 1
				 
				 * # of adults and children
				 
				  forvalues i = 1(1)9 {
					rename AGE_0`i' AGE_`i'
				  }
				 
				  forvalues i = 1(1)20 {
					generate adult`i' = .
					replace adult`i' = 1 if AGE_`i' >= 18 & AGE_`i' < .
					
					generate child`i' = .
					replace child`i' = 1 if AGE_`i' >= 0 & AGE_`i' < 18
				  }
				 
				 egen adult_n = rowtotal(adult*)
				 egen child_n = rowtotal(child*)	
				 
				  * controls similar to DHS		 
				 destring H9A H9D H9F H9G H17B, replace
				 
				 gen radio = (H9D == 1)
				 gen bicycle = (H17B == 1)
				 gen electricity = (H9A == 1)
				 gen tv = (H9E == 1)
				 gen phone = (H9F == 1| H9G == 1)
		}	 
			append using "$parentfolder/$outputfile", force	// Appending the country file to the main file
			save "$parentfolder/$outputfile", replace		

		*************** NIGERIA 2014 **********************
		{	
			use "$parentfolder/VACs/ngfemale_pubuse.dta", clear

			ren Q2 age
			keep if age >= 13 & age <= 19
			
			ren Q4 inschool
			recode inschool (2 = 0) (98/99 = .)
			
			gen hhid = hh
			rename Finalwgt finalwgt

			gen country = "Nigeria"
			
			***** physical violence in the past 12 months *****
				
				* from partner
				gen phy_partner = .
				replace phy_partner = 0 if inrange(Q100A, 1, 2) | inrange(Q100B, 1, 2) | inrange(Q100C, 1, 2) // answered yes (1) or no (2) to having experienced violence ; dropping missing answers
				replace phy_partner = 1 if Q102 == 1 | Q109 == 1 // first or most recent happened in the last 12 months
				* from peers
				gen phy_peers = .
				replace phy_peers = 0 if inrange(Q116A, 1, 2) | inrange(Q116B, 1, 2) | inrange(Q116C, 1, 2) // answered yes (1) or no (2) to having experienced violence; dropping missing answers
				replace phy_peers = 1 if Q118 == 1 | Q123 == 1 // first or most recent happened in the last 12 months
				
				* from relatives
				gen phy_relatives = .
				replace phy_relatives = 0 if inrange(Q128A, 1, 2) | inrange(Q128B, 1, 2) | inrange(Q128C, 1, 2) // answered yes (1) or no (2) to having experienced violence; dropping missing answers
				replace phy_relatives = 1 if Q130 == 1 | Q136 == 1 // first or most recent happened in the last 12 months
				
				* from other adults
				gen phy_other = .
				replace phy_other = 0 if inrange(Q142A, 1, 2) | inrange(Q142B, 1, 2) | inrange(Q142C, 1, 2) // answered yes (1) or no (2) to having experienced violence; dropping missing answers
				replace phy_other = 1 if Q144 == 1 | Q149 == 1 // first or most recent happened in the last 12 months
				* at least one incident in the past 12 months
				gen phy_violence = 0
				replace phy_violence = 1 if phy_partner == 1| phy_peers == 1 |phy_relatives == 1 | phy_other == 1
				
				* from non-partners
				gen phy_nonpartner = 0
				replace phy_nonpartner = 1 if phy_relatives == 1 | phy_other == 1

				* who are the "other adults"?
				gen phy_o_teacher = . if phy_violence == .
				replace phy_o_teacher = 0 if phy_violence != .
				replace phy_o_teacher = 1 if inlist(Q146, 1, 7) & Q144 == 1 //most recent by a male or female teacher happened in the last 12 months
				replace phy_o_teacher = 1 if inlist(Q151, 1, 7) & Q149 == 1 //most recent by a male or female teacher happened in the last 12 months
				//br phy_violence Q146 Q144 Q151 Q149 phy_o_teacher
				
				gen phy_o_police = . if phy_violence == .
				replace phy_o_police = 0 if phy_violence != .
				replace phy_o_police = 1 if inlist(Q146, 2, 8) & Q144 == 1 //most recent by a male or female police happened in the last 12 months
				replace phy_o_police = 1 if inlist(Q151, 2, 8) & Q149 == 1 //most recent by a male or female police happened in the last 12 months
				
				gen phy_o_military = .	
			
				gen phy_o_employer = . if phy_violence == .
				replace phy_o_employer = 0 if phy_violence != .
				replace phy_o_employer = 1 if inlist(Q146, 3, 9) & Q144 == 1 //most recent by a male or female employer happened in the last 12 months
				replace phy_o_employer = 1 if inlist(Q151, 3, 9) & Q149 == 1 //most recent by a male or female employer happened in the last 12 months
				
				gen phy_o_communityelder = . if phy_violence == .
				replace phy_o_communityelder = 0 if phy_violence != .
				replace phy_o_communityelder = 1 if inlist(Q146, 4, 10) & Q144 == 1 //most recent by a male or female communityelder happened in the last 12 months
				replace phy_o_communityelder = 1 if inlist(Q151, 4, 10) & Q149 == 1 //most recent by a male or female communityelder happened in the last 12 months
				
				gen phy_o_religiousleader = . if phy_violence == .
				replace phy_o_religiousleader = 0 if phy_violence != .
				replace phy_o_religiousleader = 1 if inlist(Q146, 5, 11) & Q144 == 1 //most recent by a male or female religiousleader happened in the last 12 months
				replace phy_o_religiousleader = 1 if inlist(Q151, 5, 11) & Q149 == 1 //most recent by a male or female religiousleader happened in the last 12 months
				
				gen phy_o_other = . if phy_violence == .
				replace phy_o_other = 0 if phy_violence != .
				replace phy_o_other = 1 if inlist(Q146, 6, 12, 77, 88) & Q144 == 1 //most recent by a male or female other happened in the last 12 months
				replace phy_o_other = 1 if inlist(Q151, 6, 12, 77, 88) & Q149 == 1 //most recent by a male or female other happened in the last 12 months		
			
						
						
			***** sexual violence in the past 12 months *****	
			
				* forced touch
				gen forced_touch = .
				replace forced_touch = 0 if Q700 == 2 // never attempted
				replace forced_touch = 1 if Q712 == 1 //first time happened in the last 12 months
				replace forced_touch = 0 if Q712 == 2 //first time did not happen in the last 12 months
				replace forced_touch = 1 if Q702 == 1 //most recent happened in the last 12 months
				replace forced_touch = 0 if Q702 == 2 //most recent did not happen in the last 12 months
				
				* attempted sex
				gen attempted_sex = . // attempted sex without consent
				replace attempted_sex = 0 if Q800 == 2 // never attempted
				replace attempted_sex = 1 if Q812 == 1 // first time happened in the last 12 months
				replace attempted_sex = 0 if Q812 == 2 // first time did not happen in the last 12 months
				replace attempted_sex = 1 if Q802 == 1 // most recent happened in the last 12 months
				replace attempted_sex = 0 if Q802 == 2 // most recent did not happen in the last 12 months
			
				* forced sex
				gen forced_sex = . // attempted sex without consent
				replace forced_sex = 0 if Q900 == 2 // never attempted
				replace forced_sex = 1 if Q915 == 1 //first time happened in the last 12 months
				replace forced_sex = 0 if Q915 == 2 //first time did not happen in the last 12 months
				replace forced_sex = 1 if Q902 == 1 //most recent happened in the last 12 months
				replace forced_sex = 0 if Q902 == 2 //most recent did not happen in the last 12 months	
				
				* pressured sex
				gen pressured_sex = . // attempted sex without consent
				replace pressured_sex = 0 if Q1000 == 2 // never attempted
				replace pressured_sex = 1 if Q1014 == 1 //first time happened in the last 12 months
				replace pressured_sex = 0 if Q1014 == 2 //first time did not happen in the last 12 months
				replace pressured_sex = 1 if Q1002 == 1 //most recent happened in the last 12 months
				replace pressured_sex = 0 if Q1002 == 2 //most recent did not happen in the last 12 months	
				
				* at least one incident in the past 12 months
				gen sex_violence = 0 //ever been sexually abused in the past 12 months; i.e. most recent abuse is in the past 12 months
				replace sex_violence = 1 if forced_touch == 1 | attempted_sex == 1 | forced_sex == 1 | pressured_sex == 1
			
			*****  physical or sexual violence ***** 
				gen violence = 0
				replace violence = 1 if sex_violence == 1 | phy_violence == 1
				
				
			***** sexual violence in the past 12 months in school ***** 
				
			
				* forced touch
				gen forcedtouch_inschool = .
				replace forcedtouch_inschool = 0 if Q702 == 1 // most recent in 12 months
				replace forcedtouch_inschool = 1 if Q702 == 1 & Q710 == 6 // most recent in 12 months and in school
				replace forcedtouch_inschool = 0 if Q712 == 1 //first time in 12 monthsschool
				replace forcedtouch_inschool = 1 if Q712 == 1 & Q720 == 6 // first time in 12 months and in school
			
				* attempted sex
				gen attemptedsex_inschool = .
				replace attemptedsex_inschool = 0 if Q802 == 1 // most recent in 12 months
				replace attemptedsex_inschool = 1 if Q802 == 1 & Q810 == 6 // most recent in 12 months and in school
				replace attemptedsex_inschool = 0 if Q812 == 1 //first time in 12 monthsschool
				replace attemptedsex_inschool = 1 if Q812 == 1 & Q820 == 6 // first time in 12 months and in school
				
				* forced sex
				gen forcedsex_inschool = .
				replace forcedsex_inschool = 0 if Q902 == 1 // most recent in 12 months
				replace forcedsex_inschool = 1 if Q902 == 1 & Q911 == 6 // most recent in 12 months and in school
				replace forcedsex_inschool = 0 if Q915 == 1 //first time in 12 monthsschool
				replace forcedsex_inschool = 1 if Q915 == 1 & Q924 == 6 // first time in 12 
				
				* pressured sex
				gen pressuredsex_inschool = .
				replace pressuredsex_inschool = 0 if Q1002 == 1 // most recent in 12 months
				replace pressuredsex_inschool = 1 if Q1002 == 1 & Q1010 == 6 // most recent in 12 months and in school
				replace pressuredsex_inschool = 0 if Q1014 == 1 //first time in 12 monthsschool
				replace pressuredsex_inschool = 1 if Q1014 == 1 & Q1022 == 6 // first time in 12 
				
				* violence in school
				gen sv_inschool = .
				replace sv_inschool = 0  if sex_violence == 1 //violence happened in the past year
				replace sv_inschool = 1 if forcedtouch_inschool == 1 | attemptedsex_inschool == 1 | forcedsex_inschool == 1 | pressuredsex_inschool == 1 //violence happened in the past year AND in school
				
			* additional controls
			
				* female-headed household
				 gen f_hoh = .
				 replace f_hoh = 1 if H2 == 2
				 replace f_hoh = 0 if H2 == 1
				 
				 * not with bio mom
				 gen not_wmom = .
				 replace not_wmom = 1 if Q13 == 2
				 replace not_wmom = 0 if Q13 == 1
				 
				 * not with bio dad
				 gen not_wdad = .
				 replace not_wdad = 1 if Q19 == 2
				 replace not_wdad = 0 if Q19 == 1
				 
				 * # of adults and children
				 
				  forvalues i = 1(1)9 {
					rename AGE_0`i' AGE_`i'
				  }
				 
				  forvalues i = 1(1)30 {
					generate adult`i' = .
					replace adult`i' = 1 if AGE_`i' >= 18 & AGE_`i' < .
					
					generate child`i' = .
					replace child`i' = 1 if AGE_`i' >= 0 & AGE_`i' < 18
				  }
				 
				 egen adult_n = rowtotal(adult*)
				 egen child_n = rowtotal(child*)		 
				 
			* controls similar to DHS
				
				 destring H7A H7C H7D H7E H7F H14B, replace
				 
				 gen radio = (H7C == 1)
				 gen bicycle = (H14B == 1)
				 gen electricity = (H7A == 1)
				 gen tv = (H7D == 1)
				 gen phone = (H7E == 1| H7F == 1)
		}
			append using "$parentfolder/$outputfile", force	// Appending the country file to the main file
			save "$parentfolder/$outputfile", replace		

		*************** TANZANIA 2009 **********************
		{
			use "$parentfolder/VACs/tanzfemale_04_07_11pubuse.dta", clear
			
			ren F2 age
			keep if age >= 13 & age <= 19
			
			ren F28 inschool
			recode inschool (2 = 0) (98/99 = .)
			
			egen hhid = group(CLUSTER hohdob HOHSex HOHAge HOHLive)
			
			rename postweight finalwgt
			
			gen country = "Tanzania"
			
			
			***** physical violence in the past 12 months *****
				
				* from partner
				gen phy_partner = .
				replace phy_partner = 0 if inrange(F100_AA, 1, 2) | inrange(F100_BA, 1, 2) | inrange(F100_CA, 1, 2)  // answered yes (1) or no (2) to having experienced violence ; dropping missing answers
				replace phy_partner = 1 if F100_AD == 1 | F100_BD == 1 | F100_CD == 1 // first or most recent happened in the last 12 months
				
				
				* from relatives
				gen phy_relatives = .
				replace phy_relatives = 0 if inrange(F101_A, 1, 2) | inrange(F102_A, 1, 2) // answered yes (1) or no (2) to having experienced violence; dropping missing answers
				replace phy_relatives = 1 if F101_D == 1 | F102_D == 1 // first or most recent happened in the last 12 months
				
				* from other adults
				gen phy_other = .
				replace phy_other = 0 if inrange(F103_A, 1, 2) | inrange(F104_A, 1, 2) // answered yes (1) or no (2) to having experienced violence; dropping missing answers
				replace phy_other = 1 if F103_D == 1 | F104_D == 1 // first or most recent happened in the last 12 months
				* at least one incident in the past 12 months
				gen phy_violence = 0
				replace phy_violence = 1 if phy_partner == 1 | phy_relatives == 1 | phy_other == 1
				
				* from non-partners
				gen phy_nonpartner = 0
				replace phy_nonpartner = 1 if phy_relatives == 1 | phy_other == 1
				
				* who are the "other adults"?
				gen phy_o_teacher = . if phy_violence == .
				replace phy_o_teacher = 0 if phy_violence != .
				replace phy_o_teacher = 1 if F103_E1 == 1 & F103_D == 1 // teacher punched you, kicked you, whipped you, or beat you with an object in the past 12 months
				replace phy_o_teacher = 1 if F103_E8 == 1 & F103_D == 1 // teacher punched you, kicked you, whipped you, or beat you with an object in the past 12 months
				replace phy_o_teacher = 1 if F104_E1 == 1 & F104_D == 1 // teacher used or threatened to use a knife or other weapon against you in the past 12 months
				replace phy_o_teacher = 1 if F104_E8 == 1 & F104_D == 1 // teacher used or threatened to use a knife or other weapon against you in the past 12 months
				//br phy_violence F103_E1 F103_D F104_E1 F104_D phy_o_teacher
				
				gen phy_o_police = . if phy_violence == .
				replace phy_o_police = 0 if phy_violence != .
				replace phy_o_police = 1 if F103_E2 == 1 & F103_D == 1 // police punched you, kicked you, whipped you, or beat you with an object in the past 12 months
				replace phy_o_police = 1 if F103_E9 == 1 & F103_D == 1 // police punched you, kicked you, whipped you, or beat you with an object in the past 12 months
				replace phy_o_police = 1 if F104_E2 == 1 & F104_D == 1 // police used or threatened to use a knife or other weapon against you in the past 12 months
				replace phy_o_police = 1 if F104_E9 == 1 & F104_D == 1 // police used or threatened to use a knife or other weapon against you in the past 12 months
				
				gen phy_o_military = . if phy_violence == . // drop from sample those who refused to answer any physical violence question
				replace phy_o_military = 0 if phy_violence != .
				replace phy_o_military = 1 if F103_E6 == 1 & F103_D == 1 // military punched you, kicked you, whipped you, or beat you with an object in the past 12 months
				replace phy_o_military = 1 if F103_E13 == 1 & F103_D == 1 // military punched you, kicked you, whipped you, or beat you with an object in the past 12 months
				replace phy_o_military = 1 if F104_E6 == 1 & F104_D == 1 // military used or threatened to use a knife or other weapon against you in the past 12 months
				replace phy_o_military = 1 if F104_E13 == 1 & F104_D == 1 // military used or threatened to use a knife or other weapon against you in the past 12 months
				gen phy_o_employer = .
				
				gen phy_o_communityelder = . if phy_violence == . // drop from sample those who refused to answer any physical violence question
				replace phy_o_communityelder = 0 if phy_violence != .
				replace phy_o_communityelder = 1 if F103_E3 == 1 & F103_D == 1 // communityelder punched you, kicked you, whipped you, or beat you with an object in the past 12 months
				replace phy_o_communityelder = 1 if F103_E10 == 1 & F103_D == 1 // communityelder punched you, kicked you, whipped you, or beat you with an object in the past 12 months
				replace phy_o_communityelder = 1 if F104_E3 == 1 & F104_D == 1 // communityelder used or threatened to use a knife or other weapon against you in the past 12 months
				replace phy_o_communityelder = 1 if F104_E10 == 1 & F104_D == 1 // communityelder used or threatened to use a knife or other weapon against you in the past 12 months
					
				gen phy_o_religiousleader = . if phy_violence == . // drop from sample those who refused to answer any physical violence question
				replace phy_o_religiousleader = 0 if phy_violence != .
				replace phy_o_religiousleader = 1 if F103_E5 == 1 & F103_D == 1 // religiousleader punched you, kicked you, whipped you, or beat you with an object in the past 12 months
				replace phy_o_religiousleader = 1 if F103_E12 == 1 & F103_D == 1 // religiousleader punched you, kicked you, whipped you, or beat you with an object in the past 12 months
				replace phy_o_religiousleader = 1 if F104_E5 == 1 & F104_D == 1 // religiousleader used or threatened to use a knife or other weapon against you in the past 12 months
				replace phy_o_religiousleader = 1 if F104_E12 == 1 & F104_D == 1 // religiousleader used or threatened to use a knife or other weapon against you in the past 12 months
				
				gen phy_o_other = . if phy_violence == . // drop from sample those who refused to answer any physical violence question
				replace phy_o_other = 0 if phy_violence != .
				replace phy_o_other = 1 if (F103_E7 == 1 | F103_E4 == 1 | F103_E11 == 1 | F103_E14 == 1) & F103_D == 1 // other punched you, kicked you, whipped you, or beat you with an object in the past 12 months
				replace phy_o_other = 1 if (F104_E7 == 1 | F104_E4 == 1 | F104_E11 == 1 | F104_E14 == 1) & F104_D == 1 // other punched you, kicked you, whipped you, or beat you with an object in the past 12 months
			
						
			***** sexual violence in the past 12 months *****	
			
			
				* forced touch
				gen forced_touch = .
				replace forced_touch = 0 if F301 == 0 // never attempted
				replace forced_touch = 1 if F329 == 1 //first time happened in the last 12 months
				replace forced_touch = 0 if F329 == 2 //first time did not happen in the last 12 months
				replace forced_touch = 1 if F317 == 1 //most recent happened in the last 12 months
				replace forced_touch = 0 if F317 == 2 //most recent did not happen in the last 12 months
				
				* attempted sex
				
				gen attempted_sex = . // attempted sex without consent
				replace attempted_sex = 0 if F401 == 0 // never attempted
				replace attempted_sex = 1 if F432 == 1 // first time happened in the last 12 months
				replace attempted_sex = 0 if F432 == 2 // first time did not happen in the last 12 months
				replace attempted_sex = 1 if F419 == 1 // most recent happened in the last 12 months
				replace attempted_sex = 0 if F419 == 2 // most recent did not happen in the last 12 months
				
				
				* forced sex
				gen forced_sex = .
				replace forced_sex = 0 if F501 == 0 // never attempted
				replace forced_sex = 1 if F531 == 1 //first time happened in the last 12 months
				replace forced_sex = 0 if F531 == 2 //first time did not happen in the last 12 months
				replace forced_sex = 1 if F519 == 1 //most recent happened in the last 12 months
				replace forced_sex = 0 if F519 == 2 //most recent did not happen in the last 12 months	
				
				* pressured sex
				gen pressured_sex = .
				replace pressured_sex = 0 if F601 == 0 // never attempted
				replace pressured_sex = 1 if F634 == 1 //first time happened in the last 12 months
				replace pressured_sex = 0 if F634 == 2 //first time did not happen in the last 12 months
				replace pressured_sex = 1 if F621 == 1 //most recent happened in the last 12 months
				replace pressured_sex = 0 if F621 == 2 //most recent did not happen in the last 12 months	
				
				* at least one incident in the past 12 months
				gen sex_violence = 0 //ever been sexually abused in the past 12 months; i.e. most recent abuse is in the past 12 months
				replace sex_violence = 1 if forced_touch == 1 | attempted_sex == 1 | forced_sex == 1 | pressured_sex == 1
				
				
			*****  physical or sexual violence ***** 
				gen violence = 0
				replace violence = 1 if sex_violence == 1 | phy_violence == 1
				
				
			***** sexual violence in the past 12 months in school ***** 
				
				* forced touch
				gen forcedtouch_inschool = .
				replace forcedtouch_inschool = 0 if F317 == 1 // most recent in 12 months
				replace forcedtouch_inschool = 1 if F317 == 1 & F315_4 == 1 // most recent in 12 months and in school
				replace forcedtouch_inschool = 0 if F329 == 1 //first time in 12 monthsschool
				replace forcedtouch_inschool = 1 if F329 == 1 & F326_4 == 1 // first time in 12 months and in school
			
				* attempted sex
				gen attemptedsex_inschool = .
				replace attemptedsex_inschool = 0 if F419 == 1 // most recent in 12 months
				replace attemptedsex_inschool = 1 if F419 == 1 & F417_4== 1 // most recent in 12 months and in school
				replace attemptedsex_inschool = 0 if F432 == 1 //first time in 12 monthsschool
				replace attemptedsex_inschool = 1 if F432 == 1 & F429 == 6 // first time in 12 months and in school
				
				* forced sex
				gen forcedsex_inschool = .
				replace forcedsex_inschool = 0 if F519 == 1 // most recent in 12 months
				replace forcedsex_inschool = 1 if F519 == 1 & F517_4 == 6 // most recent in 12 months and in school
				replace forcedsex_inschool = 0 if F531 == 1 //first time in 12 monthsschool
				replace forcedsex_inschool = 1 if F531 == 1 & F528_4 == 1 // first time in 12 
				
				* pressured sex
				gen pressuredsex_inschool = .
				replace pressuredsex_inschool = 0 if F621 == 1 // most recent in 12 months
				replace pressuredsex_inschool = 1 if F621 == 1 & F619_4 == 6 // most recent in 12 months and in school
				replace pressuredsex_inschool = 0 if F634 == 1 //first time in 12 monthsschool
				replace pressuredsex_inschool = 1 if F634 == 1 & F631_4 == 6 // first time in 12 
				
				* violence in school
				gen sv_inschool = .
				replace sv_inschool = 0  if sex_violence == 1 //violence happened in the past year
				replace sv_inschool = 1 if forcedtouch_inschool == 1 | attemptedsex_inschool == 1 | forcedsex_inschool == 1 | pressuredsex_inschool == 1 //violence happened in the past year AND in school
			
				* additional controls
			
				* female-headed household
				 gen f_hoh = .
				 replace f_hoh = 1 if HOHSex == "FEMALE"
				 replace f_hoh = 0 if HOHSex == "MALE"
				 
				 * not with bio mom
				 gen not_wmom = .
				 replace not_wmom = 1 if F12 == 2
				 replace not_wmom = 0 if F12 == 1
				 
				 * not with bio dad
				 gen not_wdad = .
				 replace not_wdad = 1 if F17 == 2
				 replace not_wdad = 0 if F17 == 1
				 
				 * # of adults and children
				 
				  forvalues i = 1(1)20 {
					generate adult`i' = .
					replace adult`i' = 1 if HHM`i'Age >= 18 & HHM`i'Age < .
					
					generate child`i' = .
					replace child`i' = 1 if HHM`i'Age >= 0 & HHM`i'Age < 18
				  }
				 
				 egen adult_n = rowtotal(adult*)
				 egen child_n = rowtotal(child*)	
				 
				* controls similar to DHS
				 destring H3 H22 H13_a H13_b H14_a, replace
				 rename H22 highest_schooling
				 recode highest_schooling (99 = .) (7 = 0)
				 
				 gen radio = (H13_a == 1)
				 gen bicycle = (H14_a == 1)
				 gen electricity = (H3 == 1)
				 gen tv = (H13_b)
				 gen phone = (H13_c)
		}
			append using "$parentfolder/$outputfile", force	// Appending the country file to the main file
			save "$parentfolder/$outputfile", replace		

		*************** ZAMBIA 2014 **********************
		{
			use "$parentfolder/VACs/zmfemale_pubuse.dta", clear

			ren q2 age
			keep if age >= 13 & age <= 19

			ren q4 inschool
			recode inschool (2 = 0) (98/99 = .)

			gen hhid = hh
			
			gen country = "Zambia"
						
			***** physical violence in the past 12 months *****
				
				* from partner
				gen phy_partner = .
				replace phy_partner = 0 if inrange(q100a, 1, 2) | inrange(q100b, 1, 2) | inrange(q100c, 1, 2) // answered yes (1) or no (2) to having experienced violence ; dropping missing answers
				replace phy_partner = 1 if q102 == 1 | q109 == 1 // first or most recent happened in the last 12 months
				* from peers
				gen phy_peers = .
				replace phy_peers = 0 if inrange(q116a, 1, 2) | inrange(q116b, 1, 2) | inrange(q116c, 1, 2) // answered yes (1) or no (2) to having experienced violence; dropping missing answers
				replace phy_peers = 1 if q118 == 1 | q123 == 1 // first or most recent happened in the last 12 months
				
				* from relatives
				gen phy_relatives = .
				replace phy_relatives = 0 if inrange(q128a, 1, 2) | inrange(q128b, 1, 2) | inrange(q128c, 1, 2) // answered yes (1) or no (2) to having experienced violence; dropping missing answers
				replace phy_relatives = 1 if q130 == 1 | q136 == 1 // first or most recent happened in the last 12 months
				
				* from other adults
				gen phy_other = .
				replace phy_other = 0 if inrange(q142a, 1, 2) | inrange(q142b, 1, 2) | inrange(q142c, 1, 2) // answered yes (1) or no (2) to having experienced violence; dropping missing answers
				replace phy_other = 1 if q144 == 1 | q149 == 1 // first or most recent happened in the last 12 months
				* at least one incident in the past 12 months
				gen phy_violence = 0
				replace phy_violence = 1 if phy_partner == 1| phy_peers == 1 |phy_relatives == 1 | phy_other == 1
				
				* from non-partners
				gen phy_nonpartner = 0
				replace phy_nonpartner = 1 if phy_relatives == 1 | phy_other == 1
				
				
				
				* who are the "other adults"?
				gen phy_o_teacher = . if phy_violence == .
				replace phy_o_teacher = 0 if phy_violence != .
				replace phy_o_teacher = 1 if inlist(q146, 1, 7) & q144 == 1 //most recent by a male or female teacher happened in the last 12 months
				replace phy_o_teacher = 1 if inlist(q151, 1, 7) & q149 == 1 //most recent by a male or female teacher happened in the last 12 months
				//br phy_violence q146 q144 q151 q149 phy_o_teacher
				
				gen phy_o_police = . if phy_violence == .
				replace phy_o_police = 0 if phy_violence != .
				replace phy_o_police = 1 if inlist(q146, 2, 8) & q144 == 1 //most recent by a male or female police happened in the last 12 months
				replace phy_o_police = 1 if inlist(q151, 2, 8) & q149 == 1 //most recent by a male or female police happened in the last 12 months
				
				gen phy_o_military = .	

				gen phy_o_employer = . if phy_violence == .
				replace phy_o_employer = 0 if phy_violence != .
				replace phy_o_employer = 1 if inlist(q146, 3, 9) & q144 == 1 //most recent by a male or female employer happened in the last 12 months
				replace phy_o_employer = 1 if inlist(q151, 3, 9) & q149 == 1 //most recent by a male or female employer happened in the last 12 months
				
				gen phy_o_communityelder = . if phy_violence == .
				replace phy_o_communityelder = 0 if phy_violence != .
				replace phy_o_communityelder = 1 if inlist(q146, 4, 10) & q144 == 1 //most recent by a male or female communityelder happened in the last 12 months
				replace phy_o_communityelder = 1 if inlist(q151, 4, 10) & q149 == 1 //most recent by a male or female communityelder happened in the last 12 months
				
				gen phy_o_religiousleader = . if phy_violence == .
				replace phy_o_religiousleader = 0 if phy_violence != .
				replace phy_o_religiousleader = 1 if inlist(q146, 5, 11) & q144 == 1 //most recent by a male or female religiousleader happened in the last 12 months
				replace phy_o_religiousleader = 1 if inlist(q151, 5, 11) & q149 == 1 //most recent by a male or female religiousleader happened in the last 12 months
				
				gen phy_o_other = . if phy_violence == .
				replace phy_o_other = 0 if phy_violence != .
				replace phy_o_other = 1 if inlist(q146, 6, 12, 77, 88) & q144 == 1 //most recent by a male or female other happened in the last 12 months
				replace phy_o_other = 1 if inlist(q151, 6, 12, 77, 88) & q149 == 1 //most recent by a male or female other happened in the last 12 months			

						
			***** sexual violence in the past 12 months *****	


				* forced touch
				gen forced_touch = .
				replace forced_touch = 0 if q700 == 2 // never attempted
				replace forced_touch = 1 if q712 == 1 //first time happened in the last 12 months
				replace forced_touch = 0 if q712 == 2 //first time did not happen in the last 12 months
				replace forced_touch = 1 if q702 == 1 //most recent happened in the last 12 months
				replace forced_touch = 0 if q702 == 2 //most recent did not happen in the last 12 months
				
				* attempted sex
				gen attempted_sex = . // attempted sex without consent
				replace attempted_sex = 0 if q800 == 2 // never attempted
				replace attempted_sex = 1 if q812 == 1 // first time happened in the last 12 months
				replace attempted_sex = 0 if q812 == 2 // first time did not happen in the last 12 months
				replace attempted_sex = 1 if q802 == 1 // most recent happened in the last 12 months
				replace attempted_sex = 0 if q802 == 2 // most recent did not happen in the last 12 months

				* forced sex
				gen forced_sex = . // attempted sex without consent
				replace forced_sex = 0 if q900 == 2 // never attempted
				replace forced_sex = 1 if q915 == 1 //first time happened in the last 12 months
				replace forced_sex = 0 if q915 == 2 //first time did not happen in the last 12 months
				replace forced_sex = 1 if q902 == 1 //most recent happened in the last 12 months
				replace forced_sex = 0 if q902 == 2 //most recent did not happen in the last 12 months	
				
				* pressured sex
				gen pressured_sex = . // attempted sex without consent
				replace pressured_sex = 0 if q1000 == 2 // never attempted
				replace pressured_sex = 1 if q1014 == 1 //first time happened in the last 12 months
				replace pressured_sex = 0 if q1014 == 2 //first time did not happen in the last 12 months
				replace pressured_sex = 1 if q1002 == 1 //most recent happened in the last 12 months
				replace pressured_sex = 0 if q1002 == 2 //most recent did not happen in the last 12 months	
				
				* at least one incident in the past 12 months
				gen sex_violence = 0 //ever been sexually abused in the past 12 months; i.e. most recent abuse is in the past 12 months
				replace sex_violence = 1 if forced_touch == 1 | attempted_sex == 1 | forced_sex == 1 | pressured_sex == 1
				
			*****  physical or sexual violence ***** 
				gen violence = 0
				replace violence = 1 if sex_violence == 1 | phy_violence == 1
				
			***** sexual violence in the past 12 months in school ***** 
				
				* forced touch
				gen forcedtouch_inschool = .
				replace forcedtouch_inschool = 0 if q702 == 1 // most recent in 12 months
				replace forcedtouch_inschool = 1 if q702 == 1 & q710 == 6 // most recent in 12 months and in school
				replace forcedtouch_inschool = 0 if q712 == 1 //first time in 12 monthsschool
				replace forcedtouch_inschool = 1 if q712 == 1 & q720 == 6 // first time in 12 months and in school

				* attempted sex
				gen attemptedsex_inschool = .
				replace attemptedsex_inschool = 0 if q802 == 1 // most recent in 12 months
				replace attemptedsex_inschool = 1 if q802 == 1 & q810 == 6 // most recent in 12 months and in school
				replace attemptedsex_inschool = 0 if q812 == 1 //first time in 12 monthsschool
				replace attemptedsex_inschool = 1 if q812 == 1 & q820 == 6 // first time in 12 months and in school
				
				* forced sex
				gen forcedsex_inschool = .
				replace forcedsex_inschool = 0 if q902 == 1 // most recent in 12 months
				replace forcedsex_inschool = 1 if q902 == 1 & q911 == 6 // most recent in 12 months and in school
				replace forcedsex_inschool = 0 if q915 == 1 //first time in 12 monthsschool
				replace forcedsex_inschool = 1 if q915 == 1 & q924 == 6 // first time in 12 
				
				* pressured sex
				gen pressuredsex_inschool = .
				replace pressuredsex_inschool = 0 if q1002 == 1 // most recent in 12 months
				replace pressuredsex_inschool = 1 if q1002 == 1 & q1010 == 6 // most recent in 12 months and in school
				replace pressuredsex_inschool = 0 if q1014 == 1 //first time in 12 monthsschool
				replace pressuredsex_inschool = 1 if q1014 == 1 & q1022 == 6 // first time in 12 
				
				* violence in school
				gen sv_inschool = .
				replace sv_inschool = 0  if sex_violence == 1 //violence happened in the past year
				replace sv_inschool = 1 if forcedtouch_inschool == 1 | attemptedsex_inschool == 1 | forcedsex_inschool == 1 | pressuredsex_inschool == 1 //violence happened in the past year AND in school


			* controls similar to DHS
				 destring h7a h7c h14b, replace
				 
				 gen radio = (h7c == 1)
				 gen bicycle = (h14b == 1)
				 gen electricity = (h7a == 1)
				 gen tv = (h7d == 1)
				 gen phone = (h7e == 1)
		}
			append using "$parentfolder/$outputfile", force	// Appending the country file to the main file
			save "$parentfolder/$outputfile", replace		
			

		*************** Zimbabwe 2017 **********************
		{	
			use "$parentfolder/VACs/zimbabwe_pubuse_1112021.dta", clear
			
			ren q2 age
			keep if age >= 13 & age <= 19
			keep if sex == "2" //keep girls
			
			ren q4 inschool
			recode inschool (2 = 0) (98/99 = .)
			
			egen hhid = group(geocode district1 prov ntot nsel h1_hh h1_mm h2 h3)
			
			rename finalwt finalwgt
			
			gen country = "Zimbabwe"
			
			***** physical violence in the past 12 months *****
				
				* from partner
				gen phy_partner = .
				replace phy_partner = 0 if inrange(q100a, 1, 2) | inrange(q100b, 1, 2) | inrange(q100c, 1, 2) // answered yes (1) or no (2) to having experienced violence ; dropping missing answers
				replace phy_partner = 1 if q102 == 1 | q109 == 1 // first or most recent happened in the last 12 months
				* from peers
				gen phy_peers = .
				replace phy_peers = 0 if inrange(q116a, 1, 2) | inrange(q116b, 1, 2) | inrange(q116c, 1, 2) // answered yes (1) or no (2) to having experienced violence; dropping missing answers
				replace phy_peers = 1 if q118 == 1 | q123 == 1 // first or most recent happened in the last 12 months
				
				* from relatives
				gen phy_relatives = .
				replace phy_relatives = 0 if inrange(q128a, 1, 2) | inrange(q128b, 1, 2) | inrange(q128c, 1, 2) // answered yes (1) or no (2) to having experienced violence; dropping missing answers
				replace phy_relatives = 1 if q130 == 1 | q136 == 1 // first or most recent happened in the last 12 months
				
				* from other adults
				gen phy_other = .
				replace phy_other = 0 if inrange(q142a, 1, 2) | inrange(q142b, 1, 2) | inrange(q142c, 1, 2) // answered yes (1) or no (2) to having experienced violence; dropping missing answers
				replace phy_other = 1 if q144 == 1 | q149 == 1 // first or most recent happened in the last 12 months
				* at least one incident in the past 12 months
				gen phy_violence = 0
				replace phy_violence = 1 if phy_partner == 1| phy_peers == 1 |phy_relatives == 1 | phy_other == 1
				
				* from non-partners
				gen phy_nonpartner = 0
				replace phy_nonpartner = 1 if phy_peers == 1 |phy_relatives == 1 | phy_other == 1
				
		* who are the "other adults"?
				gen phy_o_teacher = . if phy_violence == .
				replace phy_o_teacher = 0 if phy_violence != .
				replace phy_o_teacher = 1 if inlist(q146, 1, 7) & q144 == 1 //most recent by a male or female teacher happened in the last 12 months
				replace phy_o_teacher = 1 if inlist(q151, 1, 7) & q149 == 1 //most recent by a male or female teacher happened in the last 12 months
				//br phy_violence q146 q144 q151 q149 phy_o_teacher
				
				gen phy_o_police = . if phy_violence == .
				replace phy_o_police = 0 if phy_violence != .
				replace phy_o_police = 1 if inlist(q146, 2, 8) & q144 == 1 //most recent by a male or female police happened in the last 12 months
				replace phy_o_police = 1 if inlist(q151, 2, 8) & q149 == 1 //most recent by a male or female police happened in the last 12 months
				
				gen phy_o_military = .	
			
				gen phy_o_employer = . if phy_violence == .
				replace phy_o_employer = 0 if phy_violence != .
				replace phy_o_employer = 1 if inlist(q146, 3, 9) & q144 == 1 //most recent by a male or female employer happened in the last 12 months
				replace phy_o_employer = 1 if inlist(q151, 3, 9) & q149 == 1 //most recent by a male or female employer happened in the last 12 months
				
				gen phy_o_communityelder = . if phy_violence == .
				replace phy_o_communityelder = 0 if phy_violence != .
				replace phy_o_communityelder = 1 if inlist(q146, 4, 10) & q144 == 1 //most recent by a male or female communityelder happened in the last 12 months
				replace phy_o_communityelder = 1 if inlist(q151, 4, 10) & q149 == 1 //most recent by a male or female communityelder happened in the last 12 months
				
				gen phy_o_religiousleader = . if phy_violence == .
				replace phy_o_religiousleader = 0 if phy_violence != .
				replace phy_o_religiousleader = 1 if inlist(q146, 5, 11) & q144 == 1 //most recent by a male or female religiousleader happened in the last 12 months
				replace phy_o_religiousleader = 1 if inlist(q151, 5, 11) & q149 == 1 //most recent by a male or female religiousleader happened in the last 12 months
				
				gen phy_o_other = . if phy_violence == .
				replace phy_o_other = 0 if phy_violence != .
				replace phy_o_other = 1 if inlist(q146, 6, 12, 77, 88) & q144 == 1 //most recent by a male or female other happened in the last 12 months
				replace phy_o_other = 1 if inlist(q151, 6, 12, 77, 88) & q149 == 1 //most recent by a male or female other happened in the last 12 months			
				
				
				
			***** sexual violence in the past 12 months *****
			
				* forced touch
				gen forced_touch = .
				replace forced_touch = 0 if q600 == 2 |  q612 == 2 | q602 == 2 // never experienced, or first/most recent not in the past 12 months
				replace forced_touch = 1 if q612 == 1 | q602 == 1 // first/most recent happened in the last 12 months
				
				* attempted sex
				gen attempted_sex = . 
				replace attempted_sex = 0 if q700 == 2 | q712 == 2 | q702 == 2 // never attempted/ attempt did not happen in the last 12 months
				replace attempted_sex = 1 if q712 == 1 | q702 == 1 // first time/nost recent happened in the last 12 months
			
				* forced sex
				gen forced_sex = . 
				replace forced_sex = 0 if q800 == 2 | q815 == 2 | q802 == 2 // never attempted
				replace forced_sex = 1 if q815 == 1 |  q802 == 1  //first time/most recent happened in the last 12 months
				
				* pressured sex
				gen pressured_sex = . 
				replace pressured_sex = 0 if q900 == 2 | q914 == 2 | q902 == 2 // never attempted
				replace pressured_sex = 1 if q914 == 1 | q902 == 1 //first time/ most recent happened in the last 12 months
				
				* at least one incident in the past 12 months
				gen sex_violence = 0
				replace sex_violence = 1 if forced_touch == 1 | attempted_sex == 1 | forced_sex == 1 | pressured_sex == 1
				
			*****  physical or sexual violence ***** 
				gen violence = 0
				replace violence = 1 if sex_violence == 1 | phy_violence == 1
				
			*****  sexual violence in the past 12 months in school ***** 
				
				* forced touch
				gen forcedtouch_inschool = .
				replace forcedtouch_inschool = 0 if q602 == 1 // most recent in 12 months
				replace forcedtouch_inschool = 1 if q602 == 1 & q610 == 6 // most recent in 12 months and in school
				replace forcedtouch_inschool = 0 if q612 == 1 //first time in 12 monthsschool
				replace forcedtouch_inschool = 1 if q612 == 1 & q620 == 6 // first time in 12 months and in school
			
				* attempted sex
				gen attemptedsex_inschool = .
				replace attemptedsex_inschool = 0 if q702 == 1 // most recent in 12 months
				replace attemptedsex_inschool = 1 if q702 == 1 & q710 == 6 // most recent in 12 months and in school
				replace attemptedsex_inschool = 0 if q712 == 1 //first time in 12 monthsschool
				replace attemptedsex_inschool = 1 if q712 == 1 & q720 == 6 // first time in 12 months and in school
				
				* forced sex
				gen forcedsex_inschool = .
				replace forcedsex_inschool = 0 if q802 == 1 // most recent in 12 months
				replace forcedsex_inschool = 1 if q802 == 1 & q811 == 6 // most recent in 12 months and in school
				replace forcedsex_inschool = 0 if q815 == 1 //first time in 12 monthsschool
				replace forcedsex_inschool = 1 if q815 == 1 & q824 == 6 // first time in 12 
				
				* pressured sex
				gen pressuredsex_inschool = .
				replace pressuredsex_inschool = 0 if q902 == 1 // most recent in 12 months
				replace pressuredsex_inschool = 1 if q902 == 1 & q910 == 6 // most recent in 12 months and in school
				replace pressuredsex_inschool = 0 if q914 == 1 //first time in 12 monthsschool
				replace pressuredsex_inschool = 1 if q914 == 1 & q922 == 6 // first time in 12 
				
				* violence in school
				gen sv_inschool = .
				replace sv_inschool = 0  if sex_violence == 1 //violence happened in the past year
				replace sv_inschool = 1 if forcedtouch_inschool == 1 | attemptedsex_inschool == 1 | forcedsex_inschool == 1 | pressuredsex_inschool == 1 //violence happened in the past year AND in school
				

				* controls similar to DHS
				 destring h18a h18c h18d h18e h18f h19b, replace
				 
				 gen radio = (h18c == 1)
				 gen bicycle = (h19b == 1)	
				 replace bicycle = . if h19b == 99 | h19b == .
				 gen electricity = (h18a == 1)
				 gen tv = (h18d == 1)
				 recode h18e (99 = .)
				 recode h18f (99 = .)
				 gen phone = (h18e == 1 | h18f == 1)
					
		}
			append using "$parentfolder/$outputfile", force	// Appending the country file to the main file
			save "$parentfolder/$outputfile", replace		
			
/**************************************************
 02. Tables
**************************************************/
	
	/*********************************************************************
	   Table 3. Proportion of 15-19 year old girls who experienced 
	   sexual violence in the past 12 months (VACS data)
	*********************************************************************/			
	
	preserve
	
		keep if age >= 15 & age <= 19
		
		* column 2 (number of observations)
		tab country
		
		* column 3 to 8            
		tabstat sex_violence /// //at least one incident of sexual violence	 
				forced_touch /// //unwanted touch
				attempted_sex /// //attempted unwanted sex_violence
				forced_sex ///	//forced sex
				pressured_sex /// //pressured sex
				sv_inschool	/// //% of incidents that happened in school (among those who experienced violence)
				[aweight = finalwgt], by(country)
				
	restore
			
	/*********************************************************************
	   Table 4. Proportion of 15-19 year old girls who experienced 
	   sexual violence in the past 12 months 
	   according to school attendance (VACS data)
	*********************************************************************/						
		
	preserve
	
		keep if age >= 15 & age <= 19
		
		* column 2 and 5, number of girls currently attending and currently not attending school
		tab country inschool	
	
		* column 3 and 4, at least one incident of sexual violence (not currently in school)
		tabstat sex_violence sv_inschool [aweight = finalwgt] if inschool == 0, by(country)
		
		* column 6 and 7, at least one incident of sexual violence (currently in school)
		tabstat sex_violence sv_inschool [aweight = finalwgt] if inschool == 1, by(country)
			
		* column 8 and 9, simple difference
		levelsof country
			foreach countryX in `r(levels)' {
				reg sex_violence inschool [pweight = finalwgt] if country == "`countryX'"
				outreg2 using "$parentfolder/Table 4_simple difference.xls", /// // output file and formatting
							append ///
							label ///
							ctitle("`countryX', simple difference, recent sex violence")		///
							dec(3)
			}
			
		levelsof country
			foreach countryX in `r(levels)' {
				reg sv_inschool inschool [pweight = finalwgt] if country == "`countryX'"
				outreg2 using "$parentfolder/Table 4_simple difference.xls", /// // output file and formatting
							append ///
							label ///
							ctitle("`countryX', simple difference, recent sex violence at school")		///
							dec(3)
			}
		
		* column 11 and 12, adjusted difference
		levelsof country
			foreach countryX in `r(levels)' {
				reg sex_violence inschool ///
							i.age electricity radio bicycle tv phone ///
							[pweight = finalwgt] if country == "`countryX'"
				outreg2 using "$parentfolder/Table 4_adjusted difference.xls", /// // output file and formatting
							append ///
							label ///
							ctitle("`countryX', adjusted difference, recent sex violence")		///
							dec(3)
			}
			
		levelsof country
			foreach countryX in `r(levels)' {
				reg sv_inschool inschool ///
							i.age electricity radio bicycle tv phone ///
							[pweight = finalwgt] if country == "`countryX'"
				outreg2 using "$parentfolder/Table 4_adjusted difference.xls", /// // output file and formatting
							append ///
							label ///
							ctitle("`countryX', adjusted difference, recent sex violence at school")		///
							dec(3)
			}	
		
		* We check additional controls: dist_clinic highest_schooling for Kenya and highest_schooling for Tanzania. See table notes.
			reg sex_violence inschool ///
						i.age dist_clinic highest_schooling electricity radio bicycle tv phone ///
						[pweight = finalwgt] if country == "Kenya"
			outreg2 using "$parentfolder/Table 4_adjusted difference.xls", /// // output file and formatting
						append ///
						label ///
						ctitle("Kenya, adjusted diff/alternative specification, recent sex violence")		///
						dec(3)
	
			reg sv_inschool inschool ///
						i.age dist_clinic highest_schooling electricity radio bicycle tv phone ///
						[pweight = finalwgt] if country == "Kenya"
			outreg2 using "$parentfolder/Table 4_adjusted difference.xls", /// // output file and formatting
						append ///
						label ///
						ctitle("Kenya, adjusted diff/alternative specification, recent sex violence at school")		///
						dec(3)
	
			reg sex_violence inschool ///
						i.age highest_schooling electricity radio bicycle tv phone ///
						[pweight = finalwgt] if country == "Tanzania"
			outreg2 using "$parentfolder/Table 4_adjusted difference.xls", /// // output file and formatting
						append ///
						label ///
						ctitle("Tanzania, adjusted diff/alternative specification, recent sex violence")		///
						dec(3)
	
			reg sv_inschool inschool ///
						i.age highest_schooling electricity radio bicycle tv phone ///
						[pweight = finalwgt] if country == "Tanzania"
			outreg2 using "$parentfolder/Table 4_adjusted difference.xls", /// // output file and formatting
						append ///
						label ///
						ctitle("Tanzania, adjusted diff/alternative specification, recent sex violence at school")		///
						dec(3)
	restore
	
	/********************************************************************
	   Table A11. Proportion of 15-19 year old girls who reported 
	   experiencing physical violence in the past 12 months
	   according to school attendance (VACS data)
	*********************************************************************/						
	
	preserve
	
		keep if age >= 15 & age <= 19
		
		* column 2, 4 and 6, number of girls currently attending and currently not attending school
		tab country if inschool !=. 
		tab country inschool	
	
		* column 3, 5 and 7,rates of physical violence 
		tabstat phy_violence [aweight = finalwgt], by(country) // all girls
		tabstat phy_violence [aweight = finalwgt] if inschool == 0, by(country) // not in school
		tabstat phy_violence [aweight = finalwgt] if inschool == 1, by(country) // inschool
			
		* column 8, simple difference
		levelsof country
			foreach countryX in `r(levels)' {
				reg phy_violence inschool [pweight = finalwgt] if country == "`countryX'"
				outreg2 using "$parentfolder/Table A11_simple difference.xls", /// // output file and formatting
							append ///
							label ///
							ctitle("`countryX', simple difference, recent physical violence")		///
							dec(3)
			}
	
		* column 9, adjusted difference
		levelsof country
			foreach countryX in `r(levels)' {
				reg phy_violence inschool ///
							i.age electricity radio bicycle tv phone ///
							[pweight = finalwgt] if country == "`countryX'"
				outreg2 using "$parentfolder/Table A11_adjusted difference.xls", /// // output file and formatting
							append ///
							label ///
							ctitle("`countryX', adjusted difference, recent physical violence")		///
							dec(3)
			}
			
		* We check additional controls: dist_clinic highest_schooling for Kenya and highest_schooling for Tanzania. See table notes.
			reg phy_violence inschool ///
						i.age dist_clinic highest_schooling electricity radio bicycle tv phone ///
						[pweight = finalwgt] if country == "Kenya"
			outreg2 using "$parentfolder/Table A11_adjusted difference.xls", /// // output file and formatting
						append ///
						label ///
						ctitle("Kenya, adjusted diff/alternative specification, recent physical violence")		///
						dec(3)
	
			reg phy_violence inschool ///
						i.age highest_schooling electricity radio bicycle tv phone ///
						[pweight = finalwgt] if country == "Tanzania"
			outreg2 using "$parentfolder/Table A11_adjusted difference.xls", /// // output file and formatting
						append ///
						label ///
						ctitle("Tanzania, adjusted diff/alternative specification, recent physical violence")		///
						dec(3)
	restore
	
	/********************************************************************
	   Table A12. Proportion of 15-19 year old girls who reported 
	   experiencing physical violence from partners in the past 12 months
	   according to school attendance (VACS data)
	*********************************************************************/						
	
	preserve
	
		keep if age >= 15 & age <= 19
		
		* column 2, 4 and 6, number of girls currently attending and currently not attending school
		tab country if inschool !=. 
		tab country inschool	
	
		* column 3, 5 and 7,rates of physical violence from partner
		tabstat phy_partner [aweight = finalwgt], by(country) // all girls
		tabstat phy_partner [aweight = finalwgt] if inschool == 0, by(country) // not in school
		tabstat phy_partner [aweight = finalwgt] if inschool == 1, by(country) // inschool
			
		* column 8, simple difference
		levelsof country
			foreach countryX in `r(levels)' {
				reg phy_partner inschool [pweight = finalwgt] if country == "`countryX'"
				outreg2 using "$parentfolder/Table A12_simple difference.xls", /// // output file and formatting
							append ///
							label ///
							ctitle("`countryX', simple difference, recent physical violence from partner")		///
							dec(3)
			}
	
		* column 9, adjusted difference
		levelsof country
			foreach countryX in `r(levels)' {
				reg phy_partner inschool ///
							i.age electricity radio bicycle tv phone ///
							[pweight = finalwgt] if country == "`countryX'"
				outreg2 using "$parentfolder/Table A12_adjusted difference.xls", /// // output file and formatting
							append ///
							label ///
							ctitle("`countryX', adjusted difference, recent physical violence from partner")		///
							dec(3)
			}
			
		* We check additional controls: dist_clinic highest_schooling for Kenya and highest_schooling for Tanzania. See table notes.
			reg phy_partner inschool ///
						i.age dist_clinic highest_schooling electricity radio bicycle tv phone ///
						[pweight = finalwgt] if country == "Kenya"
			outreg2 using "$parentfolder/Table A12_adjusted difference.xls", /// // output file and formatting
						append ///
						label ///
						ctitle("Kenya, adjusted diff/alternative specification, recent physical violence from partner")		///
						dec(3)
	
			reg phy_partner inschool ///
						i.age highest_schooling electricity radio bicycle tv phone ///
						[pweight = finalwgt] if country == "Tanzania"
			outreg2 using "$parentfolder/Table A12_adjusted difference.xls", /// // output file and formatting
						append ///
						label ///
						ctitle("Tanzania, adjusted diff/alternative specification, recent physical violence from partner")		///
						dec(3)
						
	restore
	
	/********************************************************************
	   Table A13. Proportion of 15-19 year old girls who reported 
	   experiencing physical violence from partners in the past 12 months
	   according to school attendance (VACS data)
	*********************************************************************/						
	
	preserve
	
		keep if age >= 15 & age <= 19
		
		* column 2, 4 and 6, number of girls currently attending and currently not attending school
		tab country if inschool !=. 
		tab country inschool	
	
		* column 3, 5 and 7,rates of physical violence from nonpartner
		tabstat phy_nonpartner [aweight = finalwgt], by(country) // all girls
		tabstat phy_nonpartner [aweight = finalwgt] if inschool == 0, by(country) // not in school
		tabstat phy_nonpartner [aweight = finalwgt] if inschool == 1, by(country) // inschool
			
		* column 8, simple difference
		levelsof country
			foreach countryX in `r(levels)' {
				reg phy_nonpartner inschool [pweight = finalwgt] if country == "`countryX'"
				outreg2 using "$parentfolder/Table A13_simple difference.xls", /// // output file and formatting
							append ///
							label ///
							ctitle("`countryX', simple difference, recent physical violence from non-partner")		///
							dec(3)
			}
	
		* column 9, adjusted difference
		levelsof country
			foreach countryX in `r(levels)' {
				reg phy_nonpartner inschool ///
							i.age electricity radio bicycle tv phone ///
							[pweight = finalwgt] if country == "`countryX'"
				outreg2 using "$parentfolder/Table A13_adjusted difference.xls", /// // output file and formatting
							append ///
							label ///
							ctitle("`countryX', adjusted difference, recent physical violence from non-partner")		///
							dec(3)
			}
			
		* We check additional controls: dist_clinic highest_schooling for Kenya and highest_schooling for Tanzania. See table notes.
			reg phy_nonpartner inschool ///
						i.age dist_clinic highest_schooling electricity radio bicycle tv phone ///
						[pweight = finalwgt] if country == "Kenya"
			outreg2 using "$parentfolder/Table A13_adjusted difference.xls", /// // output file and formatting
						append ///
						label ///
						ctitle("Kenya, adjusted diff/alternative specification, recent physical violence from non-partner")		///
						dec(3)
	
			reg phy_nonpartner inschool ///
						i.age highest_schooling electricity radio bicycle tv phone ///
						[pweight = finalwgt] if country == "Tanzania"
			outreg2 using "$parentfolder/Table A13_adjusted difference.xls", /// // output file and formatting
						append ///
						label ///
						ctitle("Tanzania, adjusted diff/alternative specification, recent physical violence from non-partner")		///
						dec(3)	

	restore
	
	/********************************************************************
	   Appendix Table A14. Comparison between the adjusted difference 
	   (enrolled vs not enrolled) among the proportions of 15-19 year old girls
	   who reported experiencing physical violence
	   in the past 12 months from specific perpetrators. (VACS data)
	*********************************************************************/						
	
	preserve
	
		keep if age >= 15 & age <= 19
		
		* column 2, number of girls who answered the physical violence question
		tab country if inschool !=. 
	
		* We use capture in these regressions to drop error codes resulting from countries that do not
		* collect data for some perpetrators (and hence, regressions on those variables will result to an error).
		
		
		* column 3, adjusted difference - peers
	
			levelsof country
			foreach countryX in `r(levels)' {
				capture		reg phy_peer inschool ///
								i.age electricity radio bicycle tv phone ///
								[pweight = finalwgt] if country == "`countryX'"
				capture 	outreg2 using "$parentfolder/Table A14_adjusted difference.xls", ///
								append ///
								label ///
								ctitle("`countryX', adjusted difference, recent physical violence from peers")		///
								dec(3)
			}
			

		
		* column 4, adjusted difference - adult relatives and caregivers
			
			levelsof country
			foreach countryX in `r(levels)' {
				capture		reg phy_relatives inschool ///
								i.age electricity radio bicycle tv phone ///
								[pweight = finalwgt] if country == "`countryX'"
				capture		outreg2 using "$parentfolder/Table A14_adjusted difference.xls", ///
								append ///
								label ///
								ctitle("`countryX', adjusted difference, recent physical violence from adult relatives and caregivers")		///
								dec(3)
				}
			
			* We check additional controls: dist_clinic highest_schooling for Kenya and highest_schooling for Tanzania. See table notes.
			reg phy_relatives inschool ///
						i.age dist_clinic highest_schooling electricity radio bicycle tv phone ///
						[pweight = finalwgt] if country == "Kenya"
			outreg2 using "$parentfolder/Table A14_adjusted difference.xls", /// // output file and formatting
						append ///
						label ///
						ctitle("Kenya, adjusted diff/alternative specification, recent physical violence from adult relatives and caregivers,")		///
						dec(3)
	
			reg phy_relatives inschool ///
						i.age highest_schooling electricity radio bicycle tv phone ///
						[pweight = finalwgt] if country == "Tanzania"
			outreg2 using "$parentfolder/Table A14_adjusted difference.xls", /// // output file and formatting
						append ///
						label ///
						ctitle("Tanzania, adjusted diff/alternative specification, recent physical violence from adult relatives and caregivers")		///
						dec(3)	
		
		* column 5, adjusted difference - teacher
				
			levelsof country
			foreach countryX in `r(levels)' {
				capture 	reg phy_o_teacher inschool ///
								i.age electricity radio bicycle tv phone ///
								[pweight = finalwgt] if country == "`countryX'"
				capture 	outreg2 using "$parentfolder/Table A14_adjusted difference.xls", ///
								append ///
								label ///
								ctitle("`countryX', adjusted difference, recent physical violence from teachers")		///
								dec(3)
			}
			
			* For the table notes. We check additional controls: dist_clinic highest_schooling for Kenya and highest_schooling for Tanzania.
			reg phy_o_teacher inschool ///
						i.age dist_clinic highest_schooling electricity radio bicycle tv phone ///
						[pweight = finalwgt] if country == "Kenya"
			outreg2 using "$parentfolder/Table A14_adjusted difference.xls", /// // output file and formatting
						append ///
						label ///
						ctitle("Kenya, adjusted diff/alternative specification, recent physical violence from teachers")		///
						dec(3)
	
			reg phy_o_teacher inschool ///
						i.age highest_schooling electricity radio bicycle tv phone ///
						[pweight = finalwgt] if country == "Tanzania"
			outreg2 using "$parentfolder/Table A14_adjusted difference.xls", /// // output file and formatting
						append ///
						label ///
						ctitle("Tanzania, adjusted diff/alternative specification, recent physical violence from teachers")		///
						dec(3)		

		* column 6, adjusted difference - police
				
			levelsof country
			foreach countryX in `r(levels)' {
				capture		reg phy_o_police inschool ///
								i.age electricity radio bicycle tv phone ///
								[pweight = finalwgt] if country == "`countryX'"
				capture		outreg2 using "$parentfolder/Table A14_adjusted difference.xls", /// 
								append ///
								label ///
								ctitle("`countryX', adjusted difference, recent physical violence from police")		///
								dec(3)
			}
			
			* We check additional controls: dist_clinic highest_schooling for Kenya and highest_schooling for Tanzania. See table notes.
			reg phy_o_police inschool ///
						i.age dist_clinic highest_schooling electricity radio bicycle tv phone ///
						[pweight = finalwgt] if country == "Kenya"
			outreg2 using "$parentfolder/Table A14_adjusted difference.xls", /// // output file and formatting
						append ///
						label ///
						ctitle("Kenya, adjusted diff/alternative specification, recent physical violence from police")		///
						dec(3)
	
			reg phy_o_police inschool ///
						i.age highest_schooling electricity radio bicycle tv phone ///
						[pweight = finalwgt] if country == "Tanzania"
			outreg2 using "$parentfolder/Table A14_adjusted difference.xls", /// // output file and formatting
						append ///
						label ///
						ctitle("Tanzania, adjusted diff/alternative specification, recent physical violence from police")		///
						dec(3)		
						
		* column 7, adjusted difference - military
				
			levelsof country
			foreach countryX in `r(levels)' {
				capture 	reg phy_o_military inschool ///
								i.age electricity radio bicycle tv phone ///
								[pweight = finalwgt] if country == "`countryX'"
				capture		outreg2 using "$parentfolder/Table A14_adjusted difference.xls", ///
								append ///
								label ///
								ctitle("`countryX', adjusted difference, recent physical violence from military")		///
								dec(3)
				}
			
			* We check additional controls: dist_clinic highest_schooling for Kenya and highest_schooling for Tanzania. See table notes.
			reg phy_o_military inschool ///
						i.age dist_clinic highest_schooling electricity radio bicycle tv phone ///
						[pweight = finalwgt] if country == "Kenya"
			outreg2 using "$parentfolder/Table A14_adjusted difference.xls", /// // output file and formatting
						append ///
						label ///
						ctitle("Kenya, adjusted diff/alternative specification, recent physical violence from military")		///
						dec(3)
	
			reg phy_o_military inschool ///
						i.age highest_schooling electricity radio bicycle tv phone ///
						[pweight = finalwgt] if country == "Tanzania"
			outreg2 using "$parentfolder/Table A14_adjusted difference.xls", /// // output file and formatting
						append ///
						label ///
						ctitle("Tanzania, adjusted diff/alternative specification, recent physical violence from military")		///
						dec(3)
						
						
		* column 8, adjusted difference - employer
				
			levelsof country
			foreach countryX in `r(levels)' {
				capture 	reg phy_o_employer inschool ///
								i.age electricity radio bicycle tv phone ///
								[pweight = finalwgt] if country == "`countryX'"
				capture 	outreg2 using "$parentfolder/Table A14_adjusted difference.xls", /// 
							label ///
							ctitle("`countryX', adjusted difference, recent physical violence from employer")		///
							dec(3)
			}
			
			* We check additional controls: dist_clinic highest_schooling for Kenya. See table notes.
			reg phy_o_employer inschool ///
						i.age dist_clinic highest_schooling electricity radio bicycle tv phone ///
						[pweight = finalwgt] if country == "Kenya"
			outreg2 using "$parentfolder/Table A14_adjusted difference.xls", /// // output file and formatting
						append ///
						label ///
						ctitle("Kenya, adjusted diff/alternative specification, recent physical violence from employer")		///
						dec(3)
				
				
						
		* column 9, adjusted difference - community elder
				
			levelsof country
			foreach countryX in `r(levels)' {
				capture 	reg phy_o_communityelder inschool ///
								i.age electricity radio bicycle tv phone ///
								[pweight = finalwgt] if country == "`countryX'"
				capture 	outreg2 using "$parentfolder/Table A14_adjusted difference.xls", /// 
								append ///
								label ///
								ctitle("`countryX', adjusted difference, recent physical violence from community elder") ///
								dec(3)
			}
			
			* We check additional controls: dist_clinic highest_schooling for Kenya and highest_schooling for Tanzania. See table notes.
			reg phy_o_communityelder inschool ///
						i.age dist_clinic highest_schooling electricity radio bicycle tv phone ///
						[pweight = finalwgt] if country == "Kenya"
			outreg2 using "$parentfolder/Table A14_adjusted difference.xls", /// // output file and formatting
						append ///
						label ///
						ctitle("Kenya, adjusted diff/alternative specification, recent physical violence from community elder")		///
						dec(3)
	
			reg phy_o_communityelder inschool ///
						i.age highest_schooling electricity radio bicycle tv phone ///
						[pweight = finalwgt] if country == "Tanzania"
			outreg2 using "$parentfolder/Table A14_adjusted difference.xls", /// // output file and formatting
						append ///
						label ///
						ctitle("Tanzania, adjusted diff/alternative specification, recent physical violence from community elder")		///
						dec(3)					
						
		* column 10, adjusted difference - religious leader
				
			levelsof country
			foreach countryX in `r(levels)' {
				capture 	reg phy_o_religiousleader inschool ///
								i.age electricity radio bicycle tv phone ///
								[pweight = finalwgt] if country == "`countryX'"
				capture 	outreg2 using "$parentfolder/Table A14_adjusted difference.xls", ///
								append ///
								label ///
								ctitle("`countryX', adjusted difference, recent physical violence from religious leader") ///
								dec(3)
			}
			
			* We check additional controls: dist_clinic highest_schooling for Kenya and highest_schooling for Tanzania. See table notes.
			reg phy_o_religiousleader inschool ///
						i.age dist_clinic highest_schooling electricity radio bicycle tv phone ///
						[pweight = finalwgt] if country == "Kenya"
			outreg2 using "$parentfolder/Table A14_adjusted difference.xls", /// // output file and formatting
						append ///
						label ///
						ctitle("Kenya, adjusted diff/alternative specification, recent physical violence from religious leader")		///
						dec(3)
	
			reg phy_o_religiousleader inschool ///
						i.age highest_schooling electricity radio bicycle tv phone ///
						[pweight = finalwgt] if country == "Tanzania"
			outreg2 using "$parentfolder/Table A14_adjusted difference.xls", /// // output file and formatting
						append ///
						label ///
						ctitle("Tanzania, adjusted diff/alternative specification, recent physical violence from religious leader")		///
						dec(3)

	restore 
	
	/********************************************************************
	   Table A16. Proportion of 15-19 year old girls who reported 
	   being forced to have sex in the past 12 months
	   according to school attendance (VACS data)
	*********************************************************************/						
	
	preserve
	
		keep if age >= 15 & age <= 19
		
		* column 2, 4 and 6, number of girls currently attending and currently not attending school
		tab country if inschool !=. 
		tab country inschool	
	
		* column 3, 5 and 7,rates of being forced to have sex
		tabstat forced_sex [aweight = finalwgt], by(country) // all girls
		tabstat forced_sex [aweight = finalwgt] if inschool == 0, by(country) // not in school
		tabstat forced_sex [aweight = finalwgt] if inschool == 1, by(country) // inschool
			
		* column 8, simple difference
		levelsof country
			foreach countryX in `r(levels)' {
				reg forced_sex inschool [pweight = finalwgt] if country == "`countryX'"
				outreg2 using "$parentfolder/Table A16_simple difference.xls", /// // output file and formatting
							append ///
							label ///
							ctitle("`countryX', simple difference, being forced to have sex recently")		///
							dec(3)
			}
	
		* column 9, adjusted difference
		levelsof country
			foreach countryX in `r(levels)' {
				reg forced_sex inschool ///
							i.age electricity radio bicycle tv phone ///
							[pweight = finalwgt] if country == "`countryX'"
				outreg2 using "$parentfolder/Table A16_adjusted difference.xls", /// // output file and formatting
							append ///
							label ///
							ctitle("`countryX', adjusted difference, being forced to have sex recently")		///
							dec(3)
			}
			
		* We check additional controls: dist_clinic highest_schooling for Kenya and highest_schooling for Tanzania. See table notes.
			reg forced_sex inschool ///
						i.age dist_clinic highest_schooling electricity radio bicycle tv phone ///
						[pweight = finalwgt] if country == "Kenya"
			outreg2 using "$parentfolder/Table A16_adjusted difference.xls", /// // output file and formatting
						append ///
						label ///
						ctitle("Kenya, adjusted diff/alternative specification, being forced to have sex recently")		///
						dec(3)
	
			reg forced_sex inschool ///
						i.age highest_schooling electricity radio bicycle tv phone ///
						[pweight = finalwgt] if country == "Tanzania"
			outreg2 using "$parentfolder/Table A16_adjusted difference.xls", /// // output file and formatting
						append ///
						label ///
						ctitle("Tanzania, adjusted diff/alternative specification, being forced to have sex recently")		///
						dec(3)	
	restore
		
	
	/********************************************************************
	   Table A17. Comparison between the findings of Palermo et al. (2019)
	   and our study using the association of schooling
	   and experience of violence in the last 12 months. (VACS data)
	*********************************************************************/					
	
	preserve
	
	keep if age >= 13 & age <= 17
	keep if inlist(country, "Kenya", "Malawi", "Nigeria", "Tanzania")
	
	tab age
	
		* column 3, adjusted difference, physical violence using our analysis
		levelsof country
			foreach countryX in `r(levels)' {
				reg phy_violence inschool ///
							i.age electricity radio bicycle tv phone ///
							[pweight = finalwgt] if country == "`countryX'"
				outreg2 using "$parentfolder/Table A17_adjusted difference.xls", /// // output file and formatting
							append ///
							label ///
							ctitle("`countryX', adjusted difference, physical violence 13 to 17 (our analysis)")		///
							dec(3)
			}
			
		* column 4, adjusted difference, sexual violence using our analysis
		levelsof country
			foreach countryX in `r(levels)' {
				reg sex_violence inschool ///
							i.age electricity radio bicycle tv phone ///
							[pweight = finalwgt] if country == "`countryX'"
				outreg2 using "$parentfolder/Table A17_adjusted difference.xls", /// // output file and formatting
							append ///
							label ///
							ctitle("`countryX', adjusted difference, sexual violence 13 to 17 (our analysis)")		///
							dec(3)
			}
	
	
		* column 5, adjusted difference, physical violence using Palermo et al.'s controls
		levelsof country
			foreach countryX in `r(levels)' {
				reg phy_violence inschool ///
							i.age i.f_hoh i.not_wmom i.not_wdad adult_n child_n ///
							[pweight = finalwgt] if country == "`countryX'"
				outreg2 using "$parentfolder/Table A17_adjusted difference.xls", /// // output file and formatting
							append ///
							label ///
							ctitle("`countryX', adjusted difference, physical violence (controls from Palermo et al.)")		///
							dec(3)
			}
			
		* column 6, adjusted difference, sexual violenceusing Palermo et al.'s controls
		levelsof country
			foreach countryX in `r(levels)' {
				reg sex_violence inschool ///
							i.age i.f_hoh i.not_wmom i.not_wdad adult_n child_n ///
							[pweight = finalwgt] if country == "`countryX'"
				outreg2 using "$parentfolder/Table A17_adjusted difference.xls", /// // output file and formatting
							append ///
							label ///
							ctitle("`countryX', adjusted difference, sexual violence (controls from Palermo et al.)")		///
							dec(3)
			}
	
		* column 7, adjusted difference, physical violence using Palermo et al.'s controls and using logit
		levelsof country
			foreach countryX in `r(levels)' {
					logit phy_violence inschool ///
						i.age i.f_hoh i.not_wmom i.not_wdad adult_n child_n ///
						[pweight = finalwgt] if country == "`countryX'", or
					outreg2 using "$parentfolder/Table A17_adjusted difference.xls", /// // output file and formatting
						append ///
						dec(3) ///
						eform cti("`countryX', odds ratio")
			}
			
		* column 8, adjusted difference, sexual violenceusing Palermo et al.'s controls and using logit
		levelsof country
			foreach countryX in `r(levels)' {
				logit sex_violence inschool ///
						i.age i.f_hoh i.not_wmom i.not_wdad adult_n child_n ///
						[pweight = finalwgt] if country == "`countryX'", or
					outreg2 using "$parentfolder/Table A17_adjusted difference.xls", /// // output file and formatting
							append ///
							dec(3) ///
							eform cti("`countryX', odds ratio")
			}
	
	
	restore
			
			
	* close log file and convert to PDF

	translate "$parentfolder/$logfile.smcl" "$parentfolder/$logfile.pdf", replace
	
	*************************************** END OF CODE *****************************************
					
			
